package java_test;

import com.sun.org.apache.xml.internal.security.utils.Base64;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class testOfCredit {
    public static void main(String[] args) throws Exception {
        getEctonPublicKey("C:\\Users\\Administrator\\Desktop\\credit\\encypt.cer");
    }


    public static String getEctonPublicKey(String path )throws Exception{
        InputStream inStream = null;
        try{
            File file = new File(path);
            inStream  = new FileInputStream(file);
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream);
            String pubKeyStr = Base64.encode(cert.getPublicKey().getEncoded());

            return pubKeyStr;
        }finally {
            if (inStream != null) {
                inStream.close();
            }
        }

    }
}
